home *** CD-ROM | disk | FTP | other *** search
- <!--
- Author: stcote
- Created: 3-18-99
- Modified: 4-8-99
-
- Bugs: Timeout needed on sub-menus.
-
- -->
- <PUBLIC:Component>
- <METHOD NAME="openContextMenu" />
- <METHOD NAME="createMenuItem" />
- <METHOD NAME="createContextMenu" />
- <METHOD NAME="createMenu" / >
- <EVENT ID="onBehaviorReady" NAME="onbehaviorready" />
- <EVENT ID="onContextOpen" NAME="oncontextopen" />
- <ATTACH event="ondocumentready" handler="fnDocReady"/>
- </PUBLIC:Component>
- <SCRIPT>
- var oMenu;
- var oStyleInfo;
- var oObject=null;
- var aSubs=new Array();
- var aMenus=new Array();
-
- function fnDocReady(){
- element.oncontextmenu=openContextMenu;
- fnCreateStyleSheets();
- fnFireOnBehaviorReady("type","behavior","behaviorStatus","looks good");
- }
-
- function fnStub(){
- }
-
- function closeContextMenu(){
- oObject=null;
- window.document.releaseCapture();
- for(var i=0;i<aSubs.length;i++){
- aSubs[i].menuState=false;
- aSubs[i].style.display="none";
- if(typeof(aSubs[i]).menuItem=="object"){
- aSubs[i].menuItem.className="menuitem";
- }
- }
- }
- function openContextMenu(){
- if(typeof(aMenus[event.srcElement.nodeName])=="object"){
- oMenu=aMenus[event.srcElement.nodeName];
- if((oMenu.dependency==false)||(event.srcElement.getAttribute(oMenu.dependency))){
- if((oMenu.menuState==true)&&(event.type!="contextmenu")){
- oObject=null;
- window.document.releaseCapture();
- for(var i=0;i<aSubs.length;i++){
- aSubs[i].menuState=false;
- aSubs[i].style.display="none";
- if(typeof(aSubs[i]).menuItem=="object"){
- aSubs[i].menuItem.className="menuitem";
- }
- }
- }
- else{
- fnFireOnContextOpen("type","oncontextopen");
- oObject=event.srcElement;
- oMenu.setCapture();
- oMenu.onlosecapture=closeContextMenu;
- oMenu.menuState=true;
- oMenu.style.display="block";
- var iClientY=event.y;
- var iClientX=event.x;
- var iScrollTop=window.document.body.scrollTop;
- var iScrollLeft=window.document.body.scrollLeft;
- var iBodyWidth=window.document.body.offsetWidth;
- var iBodyHeight=window.document.body.offsetHeight;
- // alert((oMenu.offsetHeight + iClientY + iScrollTop) + "\n" + (iBodyHeight + iScrollTop));
- var iTop=0
- var iLeft=0;
- if((oMenu.offsetWidth + iClientX) < (iBodyWidth + iScrollLeft)){
- iLeft=event.clientX + iScrollLeft;
- }
- else{
- iLeft=iScrollLeft + event.clientX - oMenu.offsetWidth;
- }
- if((oMenu.offsetHeight + iClientY + iScrollTop) < (iBodyHeight + iScrollTop)){
- iTop=event.clientY + iScrollTop;
- }
- else{
- iTop=iScrollTop + event.clientY - oMenu.offsetHeight;
- }
- oMenu.style.top=iTop;
- oMenu.style.left=iLeft;
-
- }
- event.returnValue=false;
- }
- else{
- if(oMenu.menuState==true){
- closeContextMenu();
- }
- event.returnValue=true;
- }
- }
- else{
- oObject=null;
- window.document.releaseCapture();
- for(var i=0;i<aSubs.length;i++){
- aSubs[i].menuState=false;
- aSubs[i].style.display="none";
- if(typeof(aSubs[i]).menuItem=="object"){
- aSubs[i].menuItem.className="menuitem";
- }
- }
-
- }
- }
- function fnCreateStyleSheets(){
- if (!element.document.body.contextMenu){
- element.document.body.contextMenu=window.document.createStyleSheet();
- }
- oStyleInfo=element.document.body.contextMenu;
- oStyleInfo.addRule(".menu","position: absolute; display: none; background-color: #CFCFCF; width: 150; overflow-x: hidden; overflow-y: auto; border: '2 outset'; z-index: 2;");
- oStyleInfo.addRule(".menuitem","padding-left: 10px; padding-right: 6; cursor: hand; background-color: #CFCFCF; font-size: 8pt; font-family: Arial; width: 150; color: #000000;");
- oStyleInfo.addRule(".menuitem2","padding-left: 10px; padding-right: 6; cursor: hand; background-color: #0000FF; color: #FFFFFF; font-size: 8pt; font-family: Arial; width: 150;");
-
- }
- function createMenu(sElementName,sDependent){
- var oNewMenu=createContextMenu(true);
- if(arguments[1]){
- oNewMenu.dependency=sDependent;
- }
- else{
- oNewMenu.dependency=false;
- }
- aMenus[sElementName]=oNewMenu;
- return oNewMenu;
- }
- function createContextMenu(){
- oContextMenu=document.createElement("SPAN");
- oContextMenu.menuState=false;
- window.document.body.appendChild(oContextMenu);
- if(arguments[0]){
- oContextMenu.onclick=fnMenuClick;
- oContextMenu.onmouseover=fnFlash;
- oContextMenu.onmouseout=fnFlash;
- }
- aSubs[aSubs.length]=oContextMenu;
- oContextMenu.className="menu";
- return oContextMenu;
- }
- function fnMenuClick(){
- var oWorkItem=event.srcElement;
- if(oWorkItem.menu_action){
- if(oObject!=null){
- oWorkItem.menu_action();
- if(oWorkItem.hasSub==false){
- oWorkItem.className="menuitem";
- }
- }
- }
- if((oMenu.menuState==true)&&(!oWorkItem.hasSub)){
- openContextMenu();
- }
- }
- //<SPAN item_status="dull" menu_action="fnRedir(0)" ID=oCopy CLASS="menuitem">DHTML References</span>
- function createMenuItem(sTitle,fpAction,oContextMenu){
- var bSub=(arguments[3] ? true : false);
- var oItem=document.createElement("SPAN");
- var oTitle=document.createTextNode(sTitle);
- oItem.appendChild(oTitle);
- oItem.item_status=false;
- oItem.menu_action=fpAction;
- oItem.className="menuitem";
- oItem.hasSub=false;
- oContextMenu.appendChild(oItem);
- if(bSub==true){
- oItem.hasSub=true;
- oItem.subState=false;
- oItem.style.backgroundImage="url(/workshop/graphics/subMenu.gif)";
- oItem.style.backgroundRepeat="no-repeat";
- oItem.style.setExpression("backgroundPosition",oContextMenu.uniqueID + ".offsetWidth - 15");
- var oSubMenu=createContextMenu();
- oItem.subMenu=oSubMenu;
- oSubMenu.menuItem=oItem;
- }
- return oItem;
- }
- function fnFlash(){
- var oWorkItem=event.srcElement;
- var sType=event.type;
- // If this is a menu item:
- if(oWorkItem.menu_action){
- // If this is the mouseover event:
- if(sType=="mouseover"){
- // Set the menu item to a 'flash' state
- oWorkItem.className="menuitem2";
- // Set a boolean to indicate the state.
- oWorkItem.item_status="flash";
- // If this menu item has a sub menu:
- if(oWorkItem.hasSub==true){
- // Retrieve the object reference to the sub menu
- var oSub=oWorkItem.subMenu;
- // Retrieve the object reference to the menu item parent
- var oParent=oWorkItem.parentNode;
- // Set a boolean on the menu item and sub menu to indicate the sub menu is open.
- oWorkItem.subState=true;
- oSub.menuState=true;
- // Move the sub menu to an offset of the menu item
- var iOffsetLeft=oParent.offsetLeft + oParent.offsetWidth - 5;
- var iOffsetTop=oParent.offsetTop;
- var iScrollTop=window.document.body.scrollTop;
- var iScrollLeft=window.document.body.scrollLeft;
- var iBodyWidth=window.document.body.offsetWidth;
- var iBodyHeight=window.document.body.offsetHeight;
-
- var iTop=0
- var iLeft=0;
- oSub.style.display="block";
- // alert((oSub.offsetWidth) + "\n" + (iBodyWidth + iScrollLeft));
- // if((oSub.offsetWidth + iOffsetLeft + iScrollLeft) < (iBodyWidth + iScrollLeft)){
- iLeft=iOffsetLeft - 5;
- // }
- // else{
- // iLeft=iOffsetLeft - oSub.offsetWidth - 5;
- // }
- // if((oSub.offsetHeight + iOffsetTop + iScrollTop) < (iBodyHeight + iScrollTop)){
- iTop=iOffsetTop;
- // }
- // else{
- // iTop=iOffsetTop;
- // }
-
- oSub.style.top=iTop;
- oSub.style.left=iLeft;
-
- // Display the sub menu.
- }
- }
- if(sType=="mouseout"){
- // If the menu item has an open sub menu, close it.
- if((oWorkItem.hasSub==true)&&(oWorkItem.subState==true)){
- var oSub=oWorkItem.subMenu;
- // Only close the sub menu if the mouse is not moving to the sub menu.
- if(event.toElement!=oSub){
- oSub.style.display="none";
- oSub.menuState=false;
- oWorkItem.subState=false;
- oWorkItem.className="menuitem";
- }
- }
- else{
- oWorkItem.className="menuitem";
- }
- }
- }
- }
- function fnFireOnContextOpen(sName, sValue){
- var oEvent=createEventObject();
- oEvent.setAttribute(sName,sValue);
- onContextOpen.fire(oEvent);
- }
- function fnFireOnBehaviorReady(sName, sValue, sEnv, sEnvVal){
- var oEvent=createEventObject();
- oEvent.setAttribute(sName,sValue);
- oEvent.setAttribute(sEnv,sEnvVal);
- onBehaviorReady.fire(oEvent);
- }
- </SCRIPT>